package com.hxzy.shop.marketing.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;

import java.util.Date;
import java.util.UUID;

/**
 * @Description
 * @Author tu-jia-hao
 * @Data 2022/7/16 13:38
 */
public class IDUtils {

    private static byte[] lock = new byte[0];

    // 位数，默认是8位
    private final static long w = 1000;

    public static String createID() {
        String string = UUID.randomUUID().toString();
        long r = 0;
        synchronized (lock) {
            r = (long) ((Math.random() + 1) * w);
        }
        return System.currentTimeMillis() + String.valueOf(r).substring(1);
    }

    public static void main(String[] args) {
        Date date = new Date();
        String format = DateUtil.format(date, "yyyy-MM-dd HH");
        DateTime parse = DateUtil.parse(format, "yyyy-MM-dd HH");

        DateTime startTimeDate = DateUtil.parse("2022-7-19");
        DateTime endTimeDate = DateUtil.parse("2022-6-19");

        long between = DateUtil.between(startTimeDate, endTimeDate, DateUnit.DAY);


        for(int i=0;i<=between;i++){
            DateTime dateTime = DateUtil.offsetDay(startTimeDate, -i);
            System.out.println(dateTime+"===");

        }
//        System.out.println(between);
//        System.out.println(DateUtil.formatDate(date)+"  ");
//        System.out.println("======"+parse+" ====="+format+"======");
    }

}
